import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, Platform, LoadingController } from 'ionic-angular';
import { UiserviceProvider } from '../../providers/uiservice/uiservice';
import { BusiserviceProvider } from '../../providers/busiservice/busiservice';
import { LoadingUtil } from '../../common/loading';

/**
 * Generated class for the MyPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-my',
  templateUrl: 'my.html',
})
export class MyPage {
  loading:LoadingUtil;
  constructor(public navCtrl: NavController, public navParams: NavParams,
    private loadingCtrl: LoadingController, public busi: BusiserviceProvider, private uiservice: UiserviceProvider,private platform: Platform) {
      this.loading = new LoadingUtil(this.loadingCtrl);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MyPage');
  }
  getMyCard() {
    this.loading.showLoading();
    this.busi.getMyCard().subscribe(
      data => {
        this.loading.hideLoading();
        if (data._success) {
          this.navCtrl.push("MycardPage",{mycard:data.result});
        } else {
          alert(data._message);
        }
      },
      error => {
        this.loading.hideLoading();
        alert("网络异常！");
      }
    )
  }
  exit() {
    this.platform.exitApp();
  }
  getMyFavCard(){
    this.loading.showLoading();
    this.busi.getMyFavCard().subscribe(
      data=>{
        this.loading.hideLoading();
        if(data._success){  
          this.navCtrl.push("MyfavcardlistPage",{favcardlist:data.result});
        }else{
          this.uiservice.showAlert(data._message);
        }
      },
      error=>{
        this.loading.hideLoading();
        this.uiservice.showAlert("网络错误！")
      }
    )
  }
  passwordchange(){
    this.navCtrl.push("ChangepasswordPage");
  }

}
